package com.yonyou.brigade.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.yonyou.brigade.basic_init.enums.ChannelEnum;
import com.yonyou.brigade.basic_init.enums.OpenTypeEnum;
import com.yonyou.brigade.basic_init.model.BriChannel;
import com.yonyou.brigade.basic_init.service.*;
import com.yonyou.brigade.order_center.service.*;
import com.yonyou.brigade.rtpnr.model.PushTravelApplyOrder;
import com.yonyou.brigade.rtpnr.model.RtpnrUser;
import com.yonyou.brigade.rtpnr.service.IRtpnrPublicService;
import com.yonyou.brigade.rtpnr.service.IRtpnrUserService;
import com.yonyou.brigade.service.IBrigadePublicService;
import com.yonyou.brigade.third_parties.bfjr.service.IBfjrPublicService;
import com.yonyou.brigade.third_parties.bfjr.service.IBfjrUserService;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.service.ICtripGroupMemberService;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.service.ICtripGroupService;
import com.yonyou.brigade.third_parties.ctripBC.service.ICtripBCPublicService;
import com.yonyou.brigade.third_parties.didi.service.IDiDiUserService;
import com.yonyou.brigade.third_parties.fanscar.service.IFanscarPublicService;
import com.yonyou.brigade.third_parties.fanscar.service.IFanscarUserService;
import com.yonyou.brigade.third_parties.hcholiday.service.IHcHolidayUserService;
import com.yonyou.brigade.third_parties.huazhu.service.IHzUserService;
import com.yonyou.brigade.third_parties.meiya.service.IMeiyaPublicService;
import com.yonyou.brigade.third_parties.meiya.service.IMeiyaUserService;
import com.yonyou.brigade.third_parties.smectrip.dao.CtripSmeUserMapper;
import com.yonyou.brigade.third_parties.smectrip.model.CtripSmeUser;
import com.yonyou.brigade.third_parties.smectrip.service.ISmeCtripPublicService;
import com.yonyou.brigade.third_parties.tujia.service.ITuJiaSSOService;
import com.yonyou.brigade.third_parties.tuniu.model.TnDeptHistory;
import com.yonyou.brigade.third_parties.tuniu.service.ITnDeptHistoryService;
import com.yonyou.brigade.third_parties.tuniu.service.ITuniuPublicService;
import com.yonyou.brigade.third_parties.tuniu.service.ITuniuUserService;
import com.yonyou.brigade.third_parties.yihao.service.ICLYHPublicService;
import com.yonyou.brigade.third_parties.yihao.service.ICLYHUserService;
import com.yonyou.brigade.third_parties.ystrip.service.IYStripUserService;
import com.yonyou.brigade.third_parties.zteitc.model.ZteUser;
import com.yonyou.brigade.third_parties.zteitc.service.IZteUserService;
import com.yonyou.brigade.third_parties.zteitc.service.IZteitcPublicService;
import com.yonyou.brigade.util.operateutil.CompareUtils;
import com.yonyou.brigade.util.operateutil.DateUtils;
import com.yonyou.brigade.util.resultutil.Msg;
import com.yonyou.brigade.util.resultutil.ResultUtil;
import com.yonyou.brigade.ybz.service.IBriOrderNoteService;
import com.yonyou.brigade.ybz.service.ICnvRegisterService;
import com.yonyou.ybzboot.starter.common.exception.BusinessException;
import com.yonyou.ybzboot.starter.mongodb.dao.IMongoDao;
import com.yonyou.ybzboot.starter.mongodb.model.CriteriaMap;
import com.yonyou.ybzboot.uc.dto.UcUserDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

@Service(version = "1.0.0")
public class BrigadePublicServiceImpl implements IBrigadePublicService {


    @Qualifier(value = "briChannelServiceImpl")
    @Autowired
    private IBriChannelService briChannelService;

    @Autowired
    @Qualifier(value = "rtpnrUserServiceImpl")
    private IRtpnrUserService rtpnrUserService;

    @Autowired
    private ICLYHPublicService clyhPublicService;

    @Autowired
    private IMeiyaPublicService meiyaPublicService;

    @Qualifier(value = "rtpnrPublicServiceImpl")
    @Autowired
    private IRtpnrPublicService iRtpnrPublicService;

    @Autowired
    @Qualifier(value = "YStripUserServiceImpl")
    private IYStripUserService iyStripUserService;

    @Autowired
    @Qualifier(value = "briFlightInfoServiceImpl")
    private IBriFlightInfoService briFlightInfoService;

    @Autowired
    @Qualifier(value = "briHotelRoomServiceImpl")
    private IBriHotelRoomService briHotelRoomService;

    @Autowired
    @Qualifier(value = "briTrainPassengerServiceImpl")
    private IBriTrainPassengerService briTrainPassengerService;

    @Autowired
    @Qualifier(value = "briTrainTicketServiceImpl")
    private IBriTrainTicketService briTrainTicketService;

    @Autowired
    @Qualifier(value = "briCarOrderServiceImpl")
    private IBriCarOrderService briCarOrderService;

    @Autowired
    @Qualifier(value = "briOrderServiceImpl")
    private IBriOrderService briOrderService;

    @Autowired
    @Qualifier("cnvRegisterServiceImpl")
    private ICnvRegisterService cnvRegisterService;

    @Autowired
    @Qualifier("userCenterServiceImpl")
    private IUserCenterService iUserCenterService;

    @Autowired
    @Qualifier("CLYHUserServiceImpl")
    private ICLYHUserService iclyhUserService;

    @Autowired
    private IDiDiUserService didiUserService;

    @Autowired
    @Qualifier("tujiaSSOServiceImpl")
    private ITuJiaSSOService iTuJiaSSOService;

    @Autowired
    @Qualifier("tuniuUserServiceImpl")
    private ITuniuUserService tuniuUserService;

    @Autowired
    @Qualifier("tuniuPublicServiceImpl")
    private ITuniuPublicService tuniuPublicService;

    @Autowired
    @Qualifier("tnDeptHistoryServiceImpl")
    private ITnDeptHistoryService tnDeptHistoryService;

    @Autowired
    @Qualifier("zteUserServiceImpl")
    private IZteUserService zteUserService;

    @Autowired
    @Qualifier("zteitcPublicServiceImpl")
    private IZteitcPublicService zteitcPublicService;

    @Autowired
    private CtripSmeUserMapper ctripSmeUserMapper;

    @Autowired
    @Qualifier("smeCtripPublicServiceImpl")
    private ISmeCtripPublicService smeCtripPublicService;

    @Autowired
    @Qualifier("ctripBCPublicServiceImpl")
    private ICtripBCPublicService ctripBCPublicService;

    @Autowired
    @Qualifier("fanscarPublicServiceImpl")
    private IFanscarPublicService fanscarPublicService;


    @Autowired
    @Qualifier("briOrderNoteServiceImpl")
    private IBriOrderNoteService briOrderNoteService;

    @Autowired
    @Qualifier("fanscarUserServiceImpl")
    private IFanscarUserService fanscarUserService;

    @Autowired
    @Qualifier("baseDocServiceImpl")
    private IBaseDocService iBaseDocService;

    @Autowired
    private IMongoDao mongoDao;

    @Autowired
    private IMeiyaUserService meiyaUserService;

    @Autowired
    private IBriSysConfigService briSysConfigService;

    @Autowired
    private ICtripGroupService ctripGroupService;

    @Autowired
    private ICtripGroupMemberService ctripGroupMemberService;

    @Autowired
    private IHcHolidayUserService hcHolidayUserService;

    @Autowired
    private IHzUserService hzUserService;

    @Autowired
    private IBfjrPublicService bfjrPublicService;

    @Autowired
    private IMongoService mongoService;

    @Autowired
    private IBfjrUserService bfjrUserService;

    private String CompareProperties = "employeeNumber,employeeName,mobilePhone,email,enabledFlag,ownerName,deptCode,userProperty1";

    private final String APPLY_INFO_SOURCE = "apply_info_source";

    private Logger logger = LoggerFactory.getLogger(BrigadePublicServiceImpl.class);

    /**
     * 友报账通过dubbo调用商旅服务的总入口
     *
     * @param json
     * @return
     */
    @Override
    public String invokeService(String json) {
        return "test";
    }

    /**
     * 友报账调用商旅服务的总入口
     *
     * @param invokeTypeInfo
     * @param params
     * @return
     */
    @Override
    public String invokeService(Map invokeTypeInfo, Map params) {
        try {
            String jsonString = "";
            String invokeType = invokeTypeInfo.get("invoke_type").toString();
            switch (invokeType) {
                case "getHotelRooms":
                    jsonString = JSON.toJSONString(getBriHotelRoomDTOList(params));
                    break;
                case "getTrainPassengers":
                    jsonString = JSON.toJSONString(getBriTrainPassengerDTOList(params));
                    break;
                case "registerOrderToConvert":
                    jsonString = JSON.toJSONString(registerOrderToConvert(params));
                    break;
                //根据报账申请单id获取记事pk
                case "getnotepkbyybzids":
                    Map result = getNotePksByYBZIds(params);
                    return JSON.toJSONString(ResultUtil.success(result));
                case "updatenotestate":
                    updateNoteState(params);
                    return JSON.toJSONString(ResultUtil.success());
                case "orgopenunopen":
                    return JSON.toJSONString(orgOpenUnopen(params));
                case "closeApplyBill":
                    jsonString = JSON.toJSONString(closeApplyBill(params));
                    break;
                case"ctripGroupService":
                    return ctripGroupService.invokeMethod(invokeTypeInfo.get("methodName").toString(), params);
                case"ctripGroupMemberService":
                    return ctripGroupMemberService.invokeMethod(invokeTypeInfo.get("methodName").toString(), params);
                default:
                    break;
            }
            return jsonString;
        } catch (Exception e) {
            return JSON.toJSONString(ResultUtil.error(501, e.getMessage()));
        }

    }

    private List closeApplyBill(Map params) {
        String tenantId = (String) params.get("tenantId");
        String orgPk = (String) params.get("orgPk");
        String applicationNumber = (String) params.get("applicationNumber");
        JSONObject trip = (JSONObject)params.get("trip");

        //根据租户开通
        List<BriChannel> channels = briChannelService.getEnableChannelByOpenTypeAndTenant(tenantId, 1);
        //根据组织开通
        channels.addAll(briChannelService.getEnableChannelByOpenTypeAndOrgAndTenant(tenantId, orgPk, 2));

        List result = new ArrayList();
        for (BriChannel channel : channels) {
            switch (channel.getChannel()) {
                case "fanscar":
                    result.addAll(fanscarPublicService.closeApplyOrder(applicationNumber, channel)); break;
                case"zteitc":
                    result.addAll(zteitcPublicService.closeApplyOrder(applicationNumber, channel));  break;
                case"ctripBC":
                    result.addAll((ctripBCPublicService.closeApplyOrder(channel,trip))); break;
                case "ctripSME":
                    result.addAll((smeCtripPublicService.closeApplyOrder(channel,trip)));break;

                default: break;
            }
        }
        return result;
    }

    /**
     * 根据租户查询各组织渠道是否开通，返回开通的组织和没开通的组织
     *
     * @param params
     * @return
     */
    public JSONObject orgOpenUnopen(Map params) {

        JSONObject result = new JSONObject();
        String tenantId = params.get("tenantId").toString();
        String userId = params.get("userId").toString();
        List<Map<String, String>> orgs = iBaseDocService.getOrgByTenant(tenantId, userId);
        for (ChannelEnum e : ChannelEnum.values()) {
            String orgpk;
            JSONObject resultJSON = new JSONObject();
            JSONArray openJSONArray = new JSONArray();
            JSONArray unopenJSONArray = new JSONArray();
            if ("ctripSME".equals(e.getName()) || "zteitc".equals(e.getName())) {       //携程商旅和中兴商旅是按租户开通
                if (briChannelService.getEnableChannelByTenantAndChannel(tenantId, e.getName()) != null) {
                    result.put(e.getName(), "open");
                } else {
                    result.put(e.getName(), "unopen");
                }
            } else {
                for (Map m : orgs) {
                    Iterator<Map.Entry<String, String>> it = m.entrySet().iterator();
                    while (it.hasNext()) {
                        Map.Entry<String, String> entry = it.next();
                        if ("id".equals(entry.getKey())) {
                            orgpk = entry.getValue();
                            if (briChannelService.getEnableChannelByPersonTenantOrgAndChannel(tenantId, orgpk, e.getName()) != null) {
                                openJSONArray.add(m);
                            } else {
                                unopenJSONArray.add(m);
                            }
                        }
                    }
                }
                resultJSON.put("open", openJSONArray);
                resultJSON.put("unopen", unopenJSONArray);
                result.put(e.getName(), resultJSON);
            }
        }
        return result;
    }

    /**
     * 开启商旅服务
     *
     * @param briChannelJson
     * @return
     */
    @Override
    public String openBrigade(JSONObject briChannelJson) {
        logger.info(briChannelJson.toJSONString());
        BriChannel briChannel = new BriChannel();
        briChannel.setTenant(briChannelJson.getString("tenantId"));
        briChannel.setOrgpk(briChannelJson.getString("orgpk"));
        String channel = briChannelJson.getString("channel");
        briChannel.setChannel(channel);
        JSONObject configJSON = briChannelJson.getJSONObject("config");
        briChannel.setConfig(configJSON.toJSONString());
        briChannel.setOpenType(briChannelJson.getInteger("openType"));
        briChannel.setIsPreApprove(briChannelJson.getInteger("isPreApprove"));
        briChannel.setPhone(briChannelJson.getString("phone"));
        briChannel.setCreateTime(new Date());
        briChannel.setEnable(1);
        OpenTypeEnum openTypeEnum;
        if (briChannel.getOpenType() == 1) {
            openTypeEnum = OpenTypeEnum.TENTANT;
        } else {
            openTypeEnum = OpenTypeEnum.ORG;
        }

        briChannelService.openBriChannel(briChannel, openTypeEnum);

        BriChannel briChannel1 = briChannelService.getEnableInfoByTenantOrg(briChannel.getTenant(), briChannel.getOrgpk(), briChannel.getChannel());

        /**
         * 开通之后，初始化部门信息和人员信息
         */
        switch (briChannel1.getChannel()) {
            case "tuniu":
                if (BriChannel.SYNCORGDEPT == briChannel1.getSyncOrgDept()) {
                    Wrapper<TnDeptHistory> wrapper = new EntityWrapper<>();
                    wrapper.eq(TnDeptHistory.TENANT, briChannel.getTenant());
                    wrapper.eq(TnDeptHistory.ORGPK, briChannel.getOrgpk());
                    wrapper.eq(TnDeptHistory.DEPT_LEVEL, 1);
                    List<TnDeptHistory> tnDeptHistories = tnDeptHistoryService.selectList(wrapper);
                    //绑定开通后初始化途牛部门信息
                    if (briChannel1 != null && tnDeptHistories == null || tnDeptHistories.size() == 0) {
                        tuniuPublicService.initDepart(briChannel1);
                    }
                }
                break;
            case "ctripSME":
                if (BriChannel.SYNCUSER == briChannel1.getSyncUser()) {
                    UcUserDto ucUserDtoByPhone = iUserCenterService.getCompleteUcUserDtoByPhone(briChannel.getPhone(), briChannel.getTenant());
                    if (ucUserDtoByPhone == null) {
                        throw new BusinessException("用户中心中该用户不存在 ！ phone :" + briChannel.getPhone());
                    }
                    CtripSmeUser ctripSmeUser = getCtripSMEUser(ucUserDtoByPhone, briChannel.getTenant());
                    JSONArray memberInfoModelArray = new JSONArray();
                    JSONObject memberInfoModel = new JSONObject();
                    memberInfoModel.put("EmployeeID", ctripSmeUser.getEmployeeId());
                    memberInfoModel.put("Name", ctripSmeUser.getName());
                    memberInfoModel.put("Mobile", ctripSmeUser.getMobile());
                    memberInfoModel.put("IsUsed", ctripSmeUser.getValid());
                    memberInfoModel.put("IsManager", true);
                    memberInfoModelArray.add(memberInfoModel);
                    smeCtripPublicService.syncCtripSmeUsers(briChannel.getTenant(), memberInfoModelArray, briChannel1.getConfig());
                    ctripSmeUserMapper.insert(ctripSmeUser);
                } else {
                    logger.info("该租户" + briChannel1.getTenant() + "携程商旅通开通时未设置人员同步");
                }
                break;
            default:
                break;
        }


        return briChannel1.getId().toString();
    }

    @Override
    public String loginUrl(String tenant, String org, String phone, String channel, String pageType, String pcOrH5, String jsonExt) {
        String resultUrl = "";
        logger.info("begin sso request:phone(" + phone + ")");
        // 报账传输channel时会拼接跳转页面
        String[] channelAndPageType = channel.split("_");
        channel = channelAndPageType[0];
        if (channelAndPageType.length > 1) {
            pageType = channelAndPageType[1];
        }
        switch (channel) {
            case "rtpnr":
                resultUrl = rtpnrUserService.loginUrl(tenant, org, phone, pageType, pcOrH5, jsonExt);
                break;
            case "ystrip":
                resultUrl = iyStripUserService.loginUrl(tenant, org, phone, pageType, pcOrH5, jsonExt);
                break;
            case "clyh":
                resultUrl = iclyhUserService.loginUrl(tenant, org, phone, pageType, pcOrH5, jsonExt);
                break;
            case "tujia":
                resultUrl = iTuJiaSSOService.getSSOUrl(tenant, phone);
                break;
            case "tuniu":
                resultUrl = tuniuUserService.loginUrl(tenant, org, phone, pageType, pcOrH5, jsonExt);
                break;
            case "zteitc":
                resultUrl = zteUserService.loginUrl(tenant, org, phone, pageType, pcOrH5, jsonExt);
                break;
            case "fanscar":
                resultUrl = fanscarUserService.getLoginUrl(tenant, org, phone, pageType, pcOrH5, jsonExt);
                break;
            case "didiqychuxing":
                resultUrl = didiUserService.getH5Url(tenant, org, phone);
                break;
            case "meiya":
                resultUrl = meiyaUserService.getLoginUrl(tenant, org, phone, pageType, pcOrH5, jsonExt);
                break;
            case "huazhu":
                resultUrl = hzUserService.loginUrl(tenant, org, phone, pageType, pcOrH5, jsonExt);
                break;
            case "bfjr":
                resultUrl = bfjrUserService.loginUrl(tenant, org, phone, pageType, pcOrH5, jsonExt);
                break;
            default:
                break;
        }
        return resultUrl;
    }

    @Override
    public boolean isOpen(String channel, String tenant, String org, String extJson) {
        return briChannelService.isOpen(channel, tenant, org, extJson);
    }

    /**
     * 转换平台注册
     *
     * @param params
     * @return boolean 注册结果
     */
    @Override
    public Msg registerOrderToConvert(Map params) {
        String userId = params.get("userId").toString();
        String tenantId = params.get("tenantId").toString();
        boolean success = cnvRegisterService.registerAll(userId, tenantId);
        if (success) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(3001, "调用第三方服务出错");
        }
    }

    @Override
    public String tenantOpenChannels(String tenant, String extJson) {
        String result = new JSONObject().toJSONString();
        result = briChannelService.tenantOpenChannels(tenant, extJson);
        return result;
    }

    /**
     * 获取机票订单数据
     *
     * @param params
     * @return
     */
    @Override
    public Map getBriFlightInfoDTOList(Map params) {
        return briFlightInfoService.getBriFlightInfoDTOs(params);
    }

    /**
     * 获取酒店订单数据
     *
     * @param params
     * @return
     */
    @Override
    public Map getBriHotelRoomDTOList(Map params) {
        return briHotelRoomService.getBriHotelRoomDTOs(params);
    }


    /**
     * 获取火车票订单数据
     *
     * @param params
     * @return
     */
    @Override
    public Map getBriTrainPassengerDTOList(Map params) {
        return briTrainPassengerService.getBriTrainPassengerDTOs(params);
    }

    /**
     * 获取火车票订单数据
     *
     * @param params
     * @return
     */
    @Override
    public Map getBriTrainTicketDTOList(Map params) {
        return briTrainTicketService.getBriTrainTicketDTOs(params);
    }

    /**
     * 获取用车订单数据
     *
     * @param params
     * @return
     */
    @Override
    public Map getBriCarOrderDTOList(Map params) {
        return briCarOrderService.getBriCarOrderDTOs(params);
    }

    /**
     * 获取选项的参照
     *
     * @param params
     * @return
     */
    @Override
    public Map getMenuOptions(Map params) {
        return briOrderService.getMenuOptions(params);
    }

    /**
     * 批量更新中兴已同步过的用户
     *
     * @param param
     * @return
     */
    @Override
    public String syncEmployees4Zteitc(JSONObject param) {
        List<ZteUser> list = new ArrayList<>();
        String tenant = param.getString("tenant");
        String channel = param.getString("channel");
        Integer openType = param.getInteger("openType");
        BriChannel briChannel = briChannelService.getEnableChannelByOpenType(tenant, channel, openType);
        if (briChannel == null) {
            return "该租户尚未开通中兴服务";
        } else {
            if (BriChannel.SYNCUSER == briChannel.getSyncUser()) {
                Wrapper<ZteUser> zteUserWrapper = new EntityWrapper<>();
                zteUserWrapper.eq("tenant", tenant);
                List<ZteUser> zteUsers = zteUserService.selectList(zteUserWrapper);
                if (!CollectionUtils.isEmpty(zteUsers)) {
                    for (ZteUser zteUser1 : zteUsers) {
                        if (!StringUtils.isEmpty(zteUser1.getMobilePhone())) {
                            UcUserDto ucUserDtoByPhone = iUserCenterService.listCompleteUcUserByUserMobiles4admin(zteUser1.getMobilePhone(), tenant);
                            if (ucUserDtoByPhone != null) {
                                ZteUser zteUser = getZteUser(ucUserDtoByPhone);
                                Map<String, String> compareMap = new HashMap<>();
                                String[] compareFields = CompareProperties.split(",");
                                if (compareFields != null && compareFields.length > 0) {
                                    for (int i = 0; i < compareFields.length; i++) {
                                        compareMap.put(compareFields[i], "");//此处只需要key值
                                    }
                                }
                                Map<String, Object> compareResult = CompareUtils.getModifyContent(zteUser1, zteUser, compareMap);
                                if (compareResult != null && compareResult.size() > 0) {
                                    //将用户的信息进行更新
                                    zteUser.setId(zteUser1.getId());
                                    list.add(zteUser);
                                }
                            }
                        }
                    }
                    //批量更新
                    zteitcPublicService.syncZteitcSingleUserByPhone(list, briChannel);
                    zteUserService.updateBatchById(list);
                }
            } else {
                return "该租户未配置同步人员";
            }
        }
        return "success";
    }

    @Override
    public String pushTravelApplyOrder(String tenant, String org, String channel, JSONObject applyOrderJson) {
        String result = "";
        switch (channel) {
            case "rtpnr":
                result = pushTravelApplayOrder4Ctrip(tenant, org, channel, applyOrderJson);
                break;
            case "tuniu":
                result = tuniuPublicService.pushTravelApplyOrder(tenant, org, applyOrderJson);
                break;
            default:
                result = pushTravelApplyOrder2(tenant, org, channel, applyOrderJson);
                break;
        }

        return result;
    }


    /**
     * 同步申请单到商旅服务
     *
     * @param tenant
     * @param org
     * @param applyOrderJson
     * @return
     */
    private String pushTravelApplyOrder2(String tenant, String org, String channel, JSONObject applyOrderJson) {
        boolean isOpenApi = false;
        if (!StringUtils.isEmpty(channel)) {
            isOpenApi = true;
        }
        JSONObject result = new JSONObject();
        JSONArray resultArray = new JSONArray();
        JSONArray msgArr = new JSONArray();
        boolean success = false;
        //处理申请单信息
        JSONArray nodeBusinessTravelList = applyOrderJson.getJSONArray("nodeBusinessTravelList");
        Iterator it = nodeBusinessTravelList.iterator();
        while(it.hasNext()){
            Object travel = it.next();
            JSONObject travelJson = JSON.parseObject(JSON.toJSONString(travel));
            if(StringUtils.isEmpty(travelJson.get("toCity"))||StringUtils.isEmpty(travelJson.get("fromCity"))){
                logger.info("该明细没有行程信息，不同步:"+travelJson);
                it.remove();
            }
        }
        if(CollectionUtils.isEmpty(applyOrderJson.getJSONArray("nodeBusinessTravelList"))){
            msgArr.add("没有行程明细不同步");
            result.put("msgArr", msgArr);
            result.put("success", Boolean.FALSE);
            // openApi调用时channel不为空，将结果存入mongo，便于后续查未同步的原因
            if (isOpenApi) {
                result.put("msg", "没有行程明细不同步");
                mongoService.saveApplyResultToMongo(tenant, channel, applyOrderJson, result);
            }
            return result.toString();
        }
        String butongbudedandjlxpk = briSysConfigService.getSysConfigValueByKey("gztx1qwa" , null , null);
        if(applyOrderJson.getString("djlxpk").equals(butongbudedandjlxpk)){
            return result.toString();
        }
        //根据租户开通
        List<BriChannel> channels = new CopyOnWriteArrayList<>();
        if (!isOpenApi) {
            channels = briChannelService.getEnableChannelByOpenTypeAndTenant(tenant, 1);
        } else {
            BriChannel briChannel = briChannelService.getEnableChannelByOpenType(tenant, channel, 1);
            if (briChannel != null) {
                channels.add(briChannel);
            }
        }
        resultArray.addAll(switchPush(channels, tenant, org, applyOrderJson, isOpenApi));
        //根据组织开通
        if (!isOpenApi) {
            channels = briChannelService.getEnableChannelByOpenTypeAndOrgAndTenant(tenant, org, 2);
        } else {
            BriChannel briChannel = briChannelService.getEnableChannelByTenantAndOrgAndChannelAndOpenType(tenant, org, channel, 2);
            if (briChannel != null) {
                channels.add(briChannel);
            }
        }
        resultArray.addAll(switchPush(channels, tenant, org, applyOrderJson, isOpenApi));
        if (resultArray.size() > 0) {
            for (int i = 0; i < resultArray.size(); i++) {
                JSONObject jsonObject = resultArray.getJSONObject(i);
                if (jsonObject.getBooleanValue("success") || "0".equals(jsonObject.getString("code"))) {
                    success = true;
                }
                msgArr.add(jsonObject.getString("msg"));
            }
        } else {
            msgArr.add("推送失败");
        }
        result.put("success", success);
        result.put("msgArr", msgArr);
        if (!isOpenApi) {
            // 更新存储到mongo的申请单同步结果
            try {
                CriteriaMap criteriaMap = new CriteriaMap();
                criteriaMap.put("tenantId", tenant);
                criteriaMap.put("orgPk", org);
                criteriaMap.put("billNum", applyOrderJson.getString("billNum"));
                List<HashMap> mapList = mongoDao.findByMap(criteriaMap, HashMap.class, APPLY_INFO_SOURCE);
                if (!CollectionUtils.isEmpty(mapList)) {
                    mongoDao.deleteByMap(criteriaMap, APPLY_INFO_SOURCE);
                    HashMap source = mapList.get(0);
                    source.put("msg", result);
                    mongoDao.getMongoTemplate().save(source, APPLY_INFO_SOURCE);
                }
            } catch (Throwable e) {
                logger.error("更新申请单原始数据失败");
            }
        }
        return result.toJSONString();
    }

    public String pushTravelApplayOrder4Ctrip(String tenant, String org, String channel, JSONObject applyOrderJson) {
        //把json转化成PushTravelApplyOrder
        PushTravelApplyOrder pushTravelApplyOrder = new PushTravelApplyOrder();
        pushTravelApplyOrder.setOutOrderNo(applyOrderJson.getString("OutOrderNo"));
        pushTravelApplyOrder.setStartDate(applyOrderJson.getString("StartDate"));
        pushTravelApplyOrder.setEndDate(applyOrderJson.getString("EndDate"));
        pushTravelApplyOrder.setTravelCode(applyOrderJson.getString("TravelCode"));
//        pushTravelApplyOrder.setLocationCode(applyOrderJson.getString("LocationCode"));
//        pushTravelApplyOrder.setLocationName(applyOrderJson.getString("LocationName"));
        pushTravelApplyOrder.setMatters(applyOrderJson.getString("Matters"));
        pushTravelApplyOrder.setRemark(applyOrderJson.getString("Remark"));
        pushTravelApplyOrder.setApproveType(applyOrderJson.getString("ApproveType"));
        pushTravelApplyOrder.setCreateAccount(applyOrderJson.getString("CreateAccount"));
        pushTravelApplyOrder.setIsValidateTrip(applyOrderJson.getString("IsValidateTrip"));
        pushTravelApplyOrder.setIsRental(applyOrderJson.getString("IsRental"));
        //收集userID
        Set<String> userSet = new HashSet<>();
        userSet.add(applyOrderJson.getString("CreateStaffNum"));
//        pushTravelApplyOrder.setCreateStaffNum(applyOrderJson.getString("CreateStaffNum"));

        JSONArray travelArray = applyOrderJson.getJSONArray("Travelers");
        if (travelArray != null && travelArray.size() > 0) {
            for (int i = 0; i < travelArray.size(); i++) {
                JSONObject travel = travelArray.getJSONObject(i);
                userSet.add(travel.getString("StaffNum"));
            }
        }

        Map<String, String> userId2Pcode = new HashMap<>();
        //根据userID查pcode
        List<UcUserDto> completeUcUserDtoByUserid = iUserCenterService.getCompleteUcUserDtoByUserid(
                Arrays.asList(userSet.toArray(new String[0])), tenant);
        if (completeUcUserDtoByUserid != null && completeUcUserDtoByUserid.size() > 0) {
            completeUcUserDtoByUserid.forEach(userDto -> {
                userId2Pcode.put(userDto.getUserId(), userDto.getPersonCode());
            });
        }
        logger.info("------------友报账传过来的申请人员工编号为" + applyOrderJson.getString("CreateStaffNum"));
        logger.info("------------通过userId查pCode为" + userId2Pcode.get(applyOrderJson.getString("CreateStaffNum")));
        //设置pcode
        if (StringUtils.isEmpty(userId2Pcode.get(applyOrderJson.getString("CreateStaffNum")))) {
            Wrapper<RtpnrUser> rtpnrUserWrapper = new EntityWrapper<>();
            rtpnrUserWrapper.where("user_id={0}", applyOrderJson.getString("CreateStaffNum"));
            List<RtpnrUser> rtpnrUsers = rtpnrUserService.selectList(rtpnrUserWrapper);
            if (rtpnrUsers != null && rtpnrUsers.size() > 0) {
                userId2Pcode.put(applyOrderJson.getString("CreateStaffNum"), rtpnrUsers.get(0).getStaffNum());
            }

        }
        pushTravelApplyOrder.setCreateStaffNum(userId2Pcode.get(applyOrderJson.getString("CreateStaffNum")));

        //出差人信息
        List<PushTravelApplyOrder.Traveler> travelerList = new ArrayList<>();
        if (travelArray != null && travelArray.size() > 0) {
            for (int i = 0; i < travelArray.size(); i++) {
                JSONObject travel = travelArray.getJSONObject(i);
                PushTravelApplyOrder.Traveler traveler = new PushTravelApplyOrder.Traveler();
                traveler.setStaffNum(userId2Pcode.get(travel.getString("StaffNum")));
                traveler.setTrafficCode(travel.getString("TrafficCode"));
                travelerList.add(traveler);
            }
        }
        //机票行程信息
        JSONArray flightTripArray = applyOrderJson.getJSONArray("FlightTrips");
        List<PushTravelApplyOrder.FlightTrip> flightTripList = new ArrayList<>();
        if (flightTripArray != null && flightTripArray.size() > 0) {
            for (int i = 0; i < flightTripArray.size(); i++) {
                JSONObject flightTripJSON = flightTripArray.getJSONObject(i);
                PushTravelApplyOrder.FlightTrip flightTrip = new PushTravelApplyOrder.FlightTrip();
                flightTrip.setFlightWay(flightTripJSON.getString("FlightWay"));
                flightTrip.setDepartDate(applyOrderJson.getString("StartDate"));
                flightTrip.setDepartDateBegin(flightTripJSON.getString("DepartDateBegin"));
                flightTrip.setDepartDateEnd(flightTripJSON.getString("DepartDateEnd"));
                flightTrip.setIsDomc(flightTripJSON.getString("IsDomc"));
                flightTrip.setReturnDate(applyOrderJson.getString("EndDate"));
                flightTrip.setReturnDateBegin(flightTripJSON.getString("ReturnDateBegin"));
                flightTrip.setReturnDateEnd(flightTripJSON.getString("ReturnDateEnd"));
                flightTrip.setFromCityCode(flightTripJSON.getString("FromCityCode"));
                flightTrip.setToCityCode(flightTripJSON.getString("ToCityCode"));
                flightTripList.add(flightTrip);
            }
        }
        //火车票行程信息
        JSONArray trainTripArray = applyOrderJson.getJSONArray("TrainTrips");
        List<PushTravelApplyOrder.TrainTrip> trainTripList = new ArrayList<>();
        if (trainTripArray != null && trainTripArray.size() > 0) {
            for (int i = 0; i < trainTripArray.size(); i++) {
                JSONObject trainTripJSON = trainTripArray.getJSONObject(i);
                PushTravelApplyOrder.TrainTrip trainTrip = new PushTravelApplyOrder.TrainTrip();
                trainTrip.setTripType(trainTripJSON.getString("TripType"));
                trainTrip.setDepartDate(applyOrderJson.getString("StartDate"));
                trainTrip.setDepartDateBegin(trainTripJSON.getString("DepartDateBegin"));
                trainTrip.setDepartDateEnd(trainTripJSON.getString("DepartDateEnd"));
                trainTrip.setIsDomc(trainTripJSON.getString("IsDomc"));
                trainTrip.setReturnDate(applyOrderJson.getString("EndDate"));
                trainTrip.setReturnDateBegin(trainTripJSON.getString("ReturnDateBegin"));
                trainTrip.setReturnDateEnd(trainTripJSON.getString("ReturnDateEnd"));
                trainTrip.setFromCityName(trainTripJSON.getString("FromCityName"));
                trainTrip.setToCityName(trainTripJSON.getString("ToCityName"));
                trainTripList.add(trainTrip);
            }
        }
        //酒店入住信息
        JSONArray hotelTripArray = applyOrderJson.getJSONArray("HotelTrips");
        List<PushTravelApplyOrder.HotelTrip> hotelTripList = new ArrayList<>();
        if (hotelTripArray != null && hotelTripArray.size() > 0) {
            for (int i = 0; i < hotelTripArray.size(); i++) {
                JSONObject hotelTripJSON = hotelTripArray.getJSONObject(i);
                PushTravelApplyOrder.HotelTrip hotelTrip = new PushTravelApplyOrder.HotelTrip();
                hotelTrip.setCheckInDate(hotelTripJSON.getString("CheckInDate"));
                hotelTrip.setCheckInDateBegin(hotelTripJSON.getString("CheckInDateBegin"));
                hotelTrip.setCheckInDateEnd(hotelTripJSON.getString("CheckInDateEnd"));
                hotelTrip.setIsDomc(hotelTripJSON.getString("IsDomc"));
                hotelTrip.setCheckOutDate(hotelTripJSON.getString("CheckOutDate"));
                hotelTrip.setCheckOutDateBegin(hotelTripJSON.getString("CheckOutDateBegin"));
                hotelTrip.setCheckOutDateEnd(hotelTripJSON.getString("CheckOutDateEnd"));
                hotelTrip.setToCityCode(hotelTripJSON.getString("ToCityCode"));
                hotelTrip.setToCityName(hotelTripJSON.getString("ToCityName"));
                hotelTripList.add(hotelTrip);
            }
        }
        //租车信息（目前不传）
//        JSONArray rentalTripArray = applyOrderJson.getJSONArray("RentalTrips");
//        List<PushTravelApplyOrder.RentalTrip> rentalTripList = new ArrayList<>();
//        if (rentalTripArray != null && rentalTripArray.size() > 0) {
//            for (int i = 0; i < rentalTripArray.size(); i++) {
//                JSONObject rentalTripJSON = rentalTripArray.getJSONObject(i);
//                PushTravelApplyOrder.RentalTrip rentalTrip = new PushTravelApplyOrder.RentalTrip();
//                rentalTrip.setBeginUseDate(rentalTripJSON.getString("BeginUseDate"));
//                rentalTrip.setEndUseDate(rentalTripJSON.getString("EndUseDate"));
//                rentalTrip.setIsDomc(rentalTripJSON.getString("IsDomc"));
//                rentalTrip.setToCityCodeList(rentalTripJSON.getString("ToCityCodeList"));
//                rentalTrip.setToCityNameList(rentalTripJSON.getString("ToCityNameList"));
//                rentalTripList.add(rentalTrip);
//            }
//        }
        //审批人信息（可不传）
//        PushTravelApplyOrder.ApproveAuditor approveAuditor = new PushTravelApplyOrder.ApproveAuditor();
//        approveAuditor.setAccount("");
//        approveAuditor.setStaffNum("");
//        approveAuditor.setApprovePriority("");

        pushTravelApplyOrder.setTravelers(travelerList.toArray(new PushTravelApplyOrder.Traveler[0]));
        pushTravelApplyOrder.setFlightTrips(flightTripList.toArray(new PushTravelApplyOrder.FlightTrip[0]));
        pushTravelApplyOrder.setTrainTrips(trainTripList.toArray(new PushTravelApplyOrder.TrainTrip[0]));
        pushTravelApplyOrder.setHotelTrips(hotelTripList.toArray(new PushTravelApplyOrder.HotelTrip[0]));
//        pushTravelApplyOrder.setRentalTrips(rentalTripList.toArray(new PushTravelApplyOrder.RentalTrip[0]));
//        pushTravelApplyOrder.setApproveAuditors(new PushTravelApplyOrder.ApproveAuditor[]{approveAuditor});

        JSONObject resultJSON = iRtpnrPublicService.pushTravelApplyOrder(tenant, org, pushTravelApplyOrder);
        return resultJSON.toJSONString();
    }


    private JSONArray switchPush(List<BriChannel> channels, String tenant, String org, JSONObject applyOrderJson, boolean isOpenApi) {
        JSONArray resultArray = new JSONArray();
        JSONObject jsonObject = null;
        if (CollectionUtils.isEmpty(channels)) {
            if (isOpenApi) {
                JSONObject result = new JSONObject();
                result.put("msg", "未开通商旅，请管理员登录友报账管理端，进行商旅开通操作");
                result.put("success", Boolean.FALSE);
                resultArray.add(result);
                mongoService.saveApplyResultToMongo(tenant, "", applyOrderJson, result);
            }
        }
        for (BriChannel channel : channels) {
            logger.info("tenant:" + tenant + "org:" + org + "channel:" + channel.getChannel());
            if (channel.getIsPreApprove().intValue() != 1) {
                logger.info("不是提前审批");
                if (isOpenApi) {
                    JSONObject result = new JSONObject();
                    result.put("msg", "不是提前审批");
                    result.put("success", Boolean.FALSE);
                    resultArray.add(result);
                    mongoService.saveApplyResultToMongo(tenant, channel.getChannel(), applyOrderJson, result);
                }
                continue;
            }
            // 记录申请单原始数据
            try {
                if (!isOpenApi) {
                    CriteriaMap criteriaMap = new CriteriaMap();
                    criteriaMap.put("tenantId", tenant);
                    criteriaMap.put("orgPk", org);
                    criteriaMap.put("billNum", applyOrderJson.getString("billNum"));
                    List<HashMap> hasMaps = mongoDao.findByMap(criteriaMap, HashMap.class, APPLY_INFO_SOURCE);
                    if (CollectionUtils.isEmpty(hasMaps)) {
                        Date now = Calendar.getInstance().getTime();
                        Map<String, Object> data4Mongo = new HashMap<>(16);
                        data4Mongo.put("tenantId", tenant);
                        data4Mongo.put("orgPk", org);
                        data4Mongo.put("billNum", applyOrderJson.getString("billNum"));
                        data4Mongo.put("channel", channel.getChannel());
                        data4Mongo.put("pushTime", DateUtils.dateToString(now));
                        data4Mongo.put("data", applyOrderJson);
                        mongoDao.getMongoTemplate().save(data4Mongo, APPLY_INFO_SOURCE);
                    }
                }
            } catch (Exception e) {
                logger.error("收集申请单原始数据出错");
            }
            // 申请单预处理
            prepareApplyOrder(applyOrderJson, channel, isOpenApi);

            switch (channel.getChannel()) {
                case "ctripBC":
                    jsonObject = ctripBCPublicService.pushApplayOrder(channel, tenant, org, applyOrderJson, isOpenApi);
                    jsonObject.put("msg", "ctripBC:" + jsonObject.getString("success") + " msg:" + jsonObject.getString("msg"));
                    resultArray.add(jsonObject);
                    break;
                case "ctripSME":
                    jsonObject = smeCtripPublicService.pushApplayOrder(channel, tenant, org, applyOrderJson);
                    jsonObject.put("msg", "ctripSME:" + jsonObject.getString("success") + " msg:" + jsonObject.getString("msg"));
                    resultArray.add(jsonObject);
                    break;
                case "rtpnr":
                    jsonObject = iRtpnrPublicService.pushApplayOrder(channel, tenant, org, applyOrderJson);
                    jsonObject.put("msg", "rtpnr:" + jsonObject.getString("success") + " msg:" + jsonObject.getString("msg"));
                    resultArray.add(jsonObject);
                    break;
                case "tuniu":
                    jsonObject = tuniuPublicService.pushApplayOrder(channel, tenant, org, applyOrderJson);
                    jsonObject.put("msg", "tuniu:" + jsonObject.getString("success") + " msg:" + jsonObject.getString("msg"));
                    resultArray.add(jsonObject);
                    break;
                case "zteitc":
                    jsonObject = zteitcPublicService.pushApplyOrder(channel, tenant, org, applyOrderJson);
                    jsonObject.put("msg", "zteitc:" + jsonObject.getString("success") + " msg:" + jsonObject.getString("msg"));
                    resultArray.add(jsonObject);
                    break;
                case "fanscar":
                    jsonObject = fanscarPublicService.pushApplayOrder(channel, tenant, org, applyOrderJson);
                    jsonObject.put("msg", "fanscar:" + jsonObject.getString("success") + " msg:" + jsonObject.getString("msg"));
                    resultArray.add(jsonObject);
                    break;
                case "clyh":
                    jsonObject = clyhPublicService.pushApplayOrder(channel , tenant , org , applyOrderJson, isOpenApi);
                    jsonObject.put("msg", "clyh:" + jsonObject.getString("success") + " msg:" + jsonObject.getString("msg"));
                    resultArray.add(jsonObject);
                    break;
                case "meiya":
                    jsonObject = meiyaPublicService.pushApplyOrder(channel, tenant, org, applyOrderJson);
                    jsonObject.put("msg","meiya:" + jsonObject.getString("success") + " msg:" + jsonObject.getString("msg"));
                    resultArray.add(jsonObject);
                    break;
                case "bfjr":
                    jsonObject = bfjrPublicService.pushApplyOrder(channel, tenant, org, applyOrderJson);
                    jsonObject.put("msg","bfjr:" + jsonObject.getString("success") + " msg:" + jsonObject.getString("msg"));
                    resultArray.add(jsonObject);
                    break;
                default:
                    break;
            }
        }
        return resultArray;
    }

    /**
     * 申请单信息准备
     * 1、酒店入住城市信息
     * 2、出差弹性时间
     *
     * @param applyOrderJson 申请单信息
     * @param channel        开通信息
     */
    private void prepareApplyOrder(JSONObject applyOrderJson, BriChannel channel, boolean  isOpenApi) {
        if (!isOpenApi) {
            //1、酒店入住城市信息，为提供多种入住城市管控规则准备数据，增加入驻城市集合
            JSONObject hotelCities = new JSONObject();
            Integer hotelCityStrategy = channel.getHotelCityStrategy();
//        String hotelCityStrategy = briSysConfigService.getSysConfigValueByKey(BriSysConfigEnum.HOTEL_CITY_STRATEGY.name(), channel.getTenant(), channel.getOrgpk());
//        HotelCityStrategyEnum hotelCityStrategyEnum = StringUtils.isEmpty(hotelCityStrategy) ? HotelCityStrategyEnum.NONE : HotelCityStrategyEnum.valueOf(hotelCityStrategy);
            switch (hotelCityStrategy) {
                case 0:
                    break;
                case 1:
                    hotelCities = applyOrderJson.getJSONObject("special").getJSONObject("cityCodes");
                    break;
                case 3:
                    hotelCities = applyOrderJson.getJSONObject("special").getJSONObject("cityCodes");
                    JSONArray nodeBusinessTravelList = applyOrderJson.getJSONArray("nodeBusinessTravelList");
                    for (int i = 0; i < nodeBusinessTravelList.size(); i++) {
                        JSONObject travel = nodeBusinessTravelList.getJSONObject(i);
                        String tripWay = travel.getString("tripWay");
                        // 特殊交通工具
                        List<String> specialTraffic = Arrays.asList("出租车", "公交车", "城市地铁");
                        if (specialTraffic.contains(tripWay)) {
                            hotelCities = new JSONObject();
                            break;
                        }
                    }
                    break;
                case 2:
                    Set<String> cities = new CopyOnWriteArraySet<>();
                    hotelCities = applyOrderJson.getJSONObject("special").getJSONObject("cityCodes");
                    JSONArray nodeBusinessTravelList2 = applyOrderJson.getJSONArray("nodeBusinessTravelList");
                    for (int i = 0; i < nodeBusinessTravelList2.size(); i++) {
                        JSONObject travel = nodeBusinessTravelList2.getJSONObject(i);
                        String tripType = travel.getString("tripType");
                        //只有往返才会传fromCity
                        if ("RT".equals(tripType)) {
                            cities.add(StringUtils.isEmpty(travel.getString("fromCityName")) ? travel.getString("fromCity") : travel.getString("fromCityName"));
                            cities.add(StringUtils.isEmpty(travel.getString("toCityName")) ? travel.getString("toCity") : travel.getString("toCityName"));
                        } else {
                            cities.add(StringUtils.isEmpty(travel.getString("toCityName")) ? travel.getString("toCity") : travel.getString("toCityName"));
                        }
                        if (!StringUtils.isEmpty(travel.getString("hotelCityName"))) {
                            cities.add(travel.getString("hotelCityName"));
                        }
                    }
                    if (hotelCities != null && !CollectionUtils.isEmpty(hotelCities.keySet())) {
                        Set<String> keys = hotelCities.keySet();
//                    for (String key : keys) {
//                        if (!cities.contains(key)) {
//                            hotelCities.remove(key);
//                        }
//                    }
                        Iterator it = keys.iterator();
                        while(it.hasNext()){
                            String key = (String)it.next();
                            if (!cities.contains(key)) {
                                it.remove();
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
            applyOrderJson.put("hotelCities", hotelCities);
        }
        //2、出差预订弹性时间
        String bookElasticDayConfig = String.valueOf(channel.getBookElasticDay());
//        String bookElasticDayConfig = briSysConfigService.getSysConfigValueByKey(BriSysConfigEnum.BOOK_ELASTIC_DAY.name(), channel.getTenant(), channel.getOrgpk());
        if (!StringUtils.isEmpty(bookElasticDayConfig)) {
            int bookElasticDay = Integer.parseInt(bookElasticDayConfig);
            //结束、开始时间分别加减单行时间
            Date startDate = applyOrderJson.getDate("startDate");
            Date endDate = applyOrderJson.getDate("endDate");
            Optional.ofNullable(startDate).ifPresent(sd -> applyOrderJson.put("startDate", DateUtils.plusDay(sd, -bookElasticDay)));
            Optional.ofNullable(endDate).ifPresent(ed -> applyOrderJson.put("endDate", DateUtils.plusDay(ed, bookElasticDay)));
        }
    }


    /**
     * 用户中心的用户转化为写携程商旅通用户
     *
     * @param ucUserDto
     * @return
     */
    private CtripSmeUser getCtripSMEUser(UcUserDto ucUserDto, String tenant) {
        CtripSmeUser ctripSmeUser = new CtripSmeUser();
        ctripSmeUser.setTenant(tenant);
        ctripSmeUser.setOrg(ucUserDto.getOrgPk());
        ctripSmeUser.setUserId(ucUserDto.getUserId());
        ctripSmeUser.setBirthday(ucUserDto.getBirthday());
        ctripSmeUser.setDept1(ucUserDto.getOrgName());
        ctripSmeUser.setDept2(ucUserDto.getDeptName());
        ctripSmeUser.setEmployeeId(ucUserDto.getPersonCode());
        ctripSmeUser.setEmail(ucUserDto.getEmail());
        ctripSmeUser.setMobile(ucUserDto.getPhone());
        ctripSmeUser.setName(ucUserDto.getUserName());
        ctripSmeUser.setGender("0");
        ctripSmeUser.setHasBookingForOther(0);
        ctripSmeUser.setValid(ucUserDto.getDr() == 0);
        ctripSmeUser.setaManager(true);

        return ctripSmeUser;

    }

    public Map<String, List<String>> getNotePksByYBZIds(Map<String, List<String>> map) {
        return briOrderNoteService.getNotePksByYBZIds(map);
    }

    public void updateNoteState(Map<String, Map<String, Integer>> noteStates) {
        briOrderNoteService.updateNoteState(noteStates);
    }

    public ZteUser getZteUser(UcUserDto ucUserDtoByPhone) {
        ZteUser zteUser = new ZteUser();
        zteUser.setEmployeeNumber(ucUserDtoByPhone.getPersonCode());
        zteUser.setEmployeeName(ucUserDtoByPhone.getUserName());
        zteUser.setMobilePhone(ucUserDtoByPhone.getPhone());
        zteUser.setEmail(ucUserDtoByPhone.getEmail());
        zteUser.setEnabledFlag(ucUserDtoByPhone.getValid().intValue() == 1 ? "Y" : "N");
        zteUser.setCardType("0");
        zteUser.setOwnerName(ucUserDtoByPhone.getUserName());
        zteUser.setCardNum(ucUserDtoByPhone.getPassengerId());
        zteUser.setDeptCode(ucUserDtoByPhone.getDeptCode());
        zteUser.setUserProperty1(ucUserDtoByPhone.getPostName());
        return zteUser;
    }
}
